<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;

class SearchController extends BaseController
{
    public $validate = [
        "article" => ["rules" => [
            "keywords_article" => "required|string|max:50",
            "last_id" => "max:50",
        ]],
        "user" => ["rules" => [
            "keywords_user" => "required|string|max:50",
            "last_id" => "max:50",
        ]],
    ];

    /**
     * @path /search/article
     * @category 搜索
     * @title 文章
     * @method POST
     * @params [{"name":"keywords_article","type":"text","required":1,"example":"","desc":"搜索内容"},{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":false,"list":[{"id":"文章ID","author_id":"作者ID","cover_url":"文章封面图，如1.jpg","title":"文章标题","description":"文章描述","type":"文章类型，1推荐，2原创","is_deleted":0,"is_shield":0,"created_at":"创建时间戳","collect_id":"收藏ID","package_id":"收藏夹ID","target_type":1}]}}
     */
    public function article(Request $request)
    {
        $params = $request->all();

        $data = service()->ArticleService->getSearchArticleList($params);

        return $this->apiReturn($data);
    }

    /**
     * @path /search/note
     * @category 搜索
     * @title 笔记
     * @method POST
     * @params [{"name":"keywords_note","type":"text","required":1,"example":"","desc":"搜索内容"},{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":true,"list":[{"id":"24位文章笔记或划线笔记ID","type":"笔记类型，1文章笔记，2划线笔记，3随手记","user_id":"24位用户ID","article_id":"24位文章ID","is_deleted":0,"is_public":1,"created_at":"10位时间戳","start_index":"文章节选开始索引","end_index":"文章节选结束索引","content":"笔记内容","selected":"文章节选内容","is_like":0,"is_collect":1,"user":{"id":"24位用户ID","nickname":"用户昵称","avatar":"头像，如1.jpg"},"article":{"id":"24位文章ID","cover_url":"文章封面图，如1.jpg","title":"文章标题","description":"文章描述","is_deleted":0,"is_shield":0,"created_at":"文章创建时间戳"},"count":{"comment":"评论数","like":"点赞数","collect":"收藏数"}},{"id":"24位文章笔记或划线笔记ID","type":"笔记类型，1文章笔记，2划线笔记，3随手记","user_id":"24位用户ID","article_id":"24位文章ID","is_deleted":0,"is_public":1,"created_at":"10位时间戳","start_index":"文章节选开始索引","end_index":"文章节选结束索引","content":"笔记内容","selected":"文章节选内容","is_like":0,"is_collect":1,"user":{"id":"24位用户ID","nickname":"用户昵称","avatar":"头像，如1.jpg"},"image":["1.jpg"],"article":{},"count":{"comment":"评论数","like":"点赞数","collect":"收藏数"}}]}}
     */
    public function note(Request $request)
    {
        $params = $request->all();

        $data = service()->NoteDataService->onSearchList($this->getBaseInfo($params));

        return $this->apiReturn($data);
    }

    /**
     * @path /search/topic
     * @category 搜索
     * @title 话题
     * @method POST
     * @params [{"name":"keywords_topic","type":"text","required":1,"example":"","desc":"搜索内容"},{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"message":"操作成功","result":{"have_more":false,"list":[{"id":"话题ID","description":"话题描述","title":"话题标题","is_deleted":0,"updated_at":"更新时间戳","count":{"hot":"热度值"}}]}}
     */
    public function topic(Request $request)
    {
        $params = $request->all();

        $data = service()->TopicService->getSearchTopicList($this->getBaseInfo($params));

        return $this->apiReturn($data);
    }

    /**
     * @path /search/user
     * @category 搜索
     * @title 用户
     * @method POST
     * @params [{"name":"keywords_user","type":"text","required":1,"example":"","desc":"搜索内容"},{"name":"last_id","type":"text","required":0,"example":"","desc":"【翻页时必传】当前页最后一条记录的ID"}]
     * @resBody {"success":true,"statusCode":200,"result":{"have_more":false,"list":[{"id":"用户ID","nickname":"用户昵称","avatar":"用户头像，如1.jpg","special_signature":"用户个性签名","attention_status":"关注状态，0没关系，1关注，2粉丝，3互关"}]},"message":"OK"}
     */
    public function user(Request $request)
    {
        $params = $request->all();

        $data = service()->UserService->searchUserList($params);

        return $this->apiReturn($data);
    }
}
